﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace employee.Controls
{
    public partial class emProjectDetail : common.controls.baseUserControl
    {
        public emProjectDetail()
        {
            InitializeComponent();
            projectCodeEd.isToUpperCase = true;
            projTitleEd.Enabled = false;
            projTitleEd.BackColor = common.Settings.myTheme.Info.BackColor; 
        }
        protected void SetDataSource(BindingSource dataSrc)
        {
            common.BindingLibs.BindObject(this.projectCodeEd, dataSrc, DataAccess.DataCache.myBaseDS.emProjEmployee.projectCodeColumn.ColumnName);
            common.BindingLibs.BindObject(this.startDateEd, dataSrc, DataAccess.DataCache.myBaseDS.emProjEmployee.startDateColumn.ColumnName);
            common.BindingLibs.BindObject(this.endDateEd, dataSrc, DataAccess.DataCache.myBaseDS.emProjEmployee.endDateColumn.ColumnName);
            common.BindingLibs.BindObject(this.workRoleCb, dataSrc, DataAccess.DataCache.myBaseDS.emProjEmployee.workRoleColumn.ColumnName);
            common.BindingLibs.BindObject(this.workDescEd, dataSrc, DataAccess.DataCache.myBaseDS.emProjEmployee.workDescriptionColumn.ColumnName);
            workDescEd.MaxLength = DataAccess.DataCache.myBaseDS.emProjEmployee.workDescriptionColumn.MaxLength;
        }

        public virtual void Init(BindingSource dataSrc) 
        {
            workRoleCb.LoadData();
            SetDataSource(dataSrc);
        }
        public virtual bool CheckData()
        {
            bool retVal = true;
            ClearNotifyError();
            //if (projectCodeEd.Text.Trim() == "")
            //{
            //    NotifyError(projectCodeLbl);
            //    retVal = false;
            //}
            //if (startDateEd.myValue == common.Consts.constNullDate)
            //{
            //    NotifyError(startDateLbl);
            //    retVal = false;
            //}
            //if (workRoleCb.myValue == "")
            //{
            //    NotifyError(workRoleLbl);
            //    retVal = false;
            //}
            //if (workDescEd.Text.Trim() == "")
            //{
            //    NotifyError(workDescLbl);
            //    retVal = false;
            //}
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            state = !state;
            projectCodeEd.Enabled = state;
            startDateEd.Enabled = state;
            endDateEd.Enabled = state;
            workDescEd.Enabled = state;
            workRoleCb.Enabled = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            projectCodeEd.Focus();
        }

        private void projectCodeEd_Validated(object sender, EventArgs e)
        {
            try
            {
                data.baseDS.emProjectRow projRow = DataAccess.DataLibs.FindAndCache(DataAccess.DataCache.myBaseDS.emProject, projectCodeEd.Text);
                projTitleEd.Text = "";
                if (projRow != null)
                {
                    projTitleEd.Text = projRow.title;
                }
            }
            catch (Exception er)
            {
                this.ErrorHandler(sender, er);
            }
        } 
    }
}
